// JavaScript Document
;(function(window,document){
	PLAYER=function(){
        this.videoID = PLAYER.mkVideoId();
        this.progressID=PLAYER.mkVideoId()+'__progressID';
        this.clickID=PLAYER.mkVideoId()+'__clickID';
        this.ctrlerID=PLAYER.mkVideoId()+'__ctrlerID';
        PLAYER.mkCoverDiv()
        PLAYER.mkShowDiv()
        this.mkProgress()
        this.mkClickDiv()
        PLAYER.mkDiv(this.ctrlerID,'background-color:#000;position:fixed;bottom:0px;height:50px;width:'
            +window.innerWidth+'px;'
            +'filter: alpha(opacity = 70);opacity: .7;display:none;z-index:9999'
            ,'')
			
        var that =this;
            window.addEventListener('resize', function () {
                try {

                    document.getElementById(that.videoID).setAttribute('width', window.innerWidth + 'px')
                }catch (e){console.error(e)}
            }, false)
			window.addEventListener('resize', function () {
                try {

                    document.getElementById(that.progressID).style.width= window.innerWidth + 'px' 
                }catch (e){console.error(e)}
            }, false)
			window.addEventListener('resize', function () {
                try {

                    document.getElementById(that.clickID).style.width= window.innerWidth + 'px'
					try{
					document.getElementById(that.clickID).removeEventListener("click")
					}catch(e){}
					
					document.getElementById(that.clickID).addEventListener('click',function(){
                that.goClick()
            },false) 
                }catch (e){console.error(e)}
            }, false)
			window.addEventListener('resize', function () {
                try {

                    document.getElementById(that.ctrlerID).style.width= window.innerWidth + 'px' 
                }catch (e){console.error(e)}
            }, false)
			
			 
			

    }

 	//PLAYER.prototype={ 这里不能要,要了就不能执行loopfn
	//	constructor:PLAYER
	//}
    PLAYER.prototype.player=function(){
        return document.getElementById(this.videoID);
    }
    PLAYER.mkVideoId=function(){
        return 'VID'+(new Date()).getTime()+'__'+Math.random()+'__'+
            Math.round(  Math.random()*( 9999-1 - 0) + 0  )
    }
    PLAYER.mkShowDiv=function(){
        var oDiv=document.createElement('div')
        oDiv.id='info'
        oDiv.style.cssText='position:fixed;top:30px;left:70px;z-index: 1; border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px;  background-color:#f60;padding:4px;color:#fff;filter: alpha(opacity = 90);opacity: 0.9;display:none;font-size:24px;font-family:"思源黑体 CN Light"'
        window.document.getElementsByTagName('body')[0].appendChild(oDiv)
    }
	PLAYER.prototype.mkVideo=function(src,target){
        if(typeof src === 'undefined'){
            var src = 'xx.mp4';
        }
    var oVideo=document.createElement('video');
        oVideo.setAttribute('autoplay','autoplay');
        oVideo.setAttribute('loop','loop');
        oVideo.setAttribute('width',window.innerWidth+'px');
        oVideo.id = this.videoID;
    var oSource = PLAYER.mkVideoSource(src);
        oVideo.appendChild(oSource);
    var oDiv = document.createElement('div')
        oDiv.innerHTML = 'Your browser does not support the video tag';
        oVideo.appendChild(oDiv);
	if(typeof target === 'undefined'){
         var target=window.document.getElementsByTagName('body')[0]; 
	}
		 target.appendChild(oVideo);	
	}

    PLAYER.mkVideoSource=function(src){
        var oSource=document.createElement('source');
        oSource.setAttribute('src',src);
        oSource.setAttribute('type','video/mp4')
        return oSource;
    }
    PLAYER.mkCoverDiv=function(){
        var oCoverDiv=document.createElement('div');
        oCoverDiv.style.cssText='position:fixed;top:0px; width:'+window.innerWidth+'px'
        +'; height:'+window.innerHeight+'px'+';'
        +'z-Index:99;filter: alpha(opacity=0); opacity: 0;'
		oCoverDiv.id='oCoverDiv__'+ PLAYER.mkVideoId()
        var body = window.document.getElementsByTagName('body')[0];
        body.appendChild(oCoverDiv)
    }
    PLAYER.prototype.mkProgress=function() {
        var oDiv = document.createElement('div')
        oDiv.style.cssText = 'background-color:#500389;height:50px;width:'
            + '0px;position:fixed;bottom:0px;filter: alpha(opacity = 50);opacity: 0.5;'
        oDiv.id = this.progressID;
        var that=this;
        window.setTimeout(function (){
        document.getElementById(that.ctrlerID).appendChild(oDiv)
        },0)
    }
    PLAYER.prototype.mkClickDiv=function(){
        var oDiv= document.createElement('div')
        oDiv.style.cssText='background-color:red;height:50px;z-index:200000000;width:'
            +window.innerWidth+'px;position:fixed;bottom:0px;filter: alpha(opacity = 0);opacity: 0;'
        oDiv.id= this.clickID;
        var that=this;
        window.setTimeout(function (){
            document.getElementById(that.ctrlerID).appendChild(oDiv)
            document.getElementById(that.clickID).addEventListener('click',function(){
                that.goClick()
            },false)
			  
        },100)
		 
    }
    PLAYER.prototype.goClick=function() {
        try {
       var event = event || window.event ||  arguments.callee.caller.arguments[0]/*支持火狐*/ ;
        var time = (TOOLS.getMousePagePos(event)[0] / window.innerWidth) * this.player().duration
        }catch (e){ }
        this.player().currentTime =  time ;

    }
    PLAYER.mkDiv=function(id,cssText,innerHTML){
        var innerHTML =innerHTML || "";
        var body=document.getElementsByTagName('body')[0];
        var div = document.createElement("div");
        div.id=id;
        div.innerHTML=innerHTML;
        div.style.cssText=cssText;
        try{body.insertBefore(div,body.childNodes[0]);	}catch(e){ }
    }
    window.PLAYER=PLAYER;
}(window,document))